<script type="text/javascript">
    $(document).ready(function() {
        $('.getfile').click(function() {
            window.KCFinder = {};
            window.KCFinder.callBack = function(url) {
                window.KCFinder = null;
                // Actions with url parameter here
                var id = $('.getfile').attr('rel');
                var value = url.replace('<?php echo BASE_PATH?>', '');
                $('#' + id).val(value);
                if (value) {
                    $('#show' + id).html('<img src="<?php echo BASE_PATH?>' + value + '" style="max-width:200px">')
                }
            };
            kfm_url = '<?php echo JS_PATH?>/kcfinder/browse.php';
            //window.open(kfm_url, 'kcfinder_single');
            window.open(kfm_url,"kfm","modal,width=960,height=640");
        });
        
        $('.imageinput').change(function() {
            var id = $(this).attr('id');
            if ($(this).val()) {
                $('#show' + id).html('<img src="<?php echo BASE_PATH?>' + $(this).val() + '" style="max-width:200px">')
            }
        });
    });
</script>
<h1>
<?php
$allCategory = $this->allCategory;
$pa_id = (int)$this->pa_id;

if ($pa_id > 0) {
    @$allParent = $allCategory[$pa_id]['all_parent'];
    
    $arrParent = explode(',', $allParent);
    $arrParent[] = $pa_id;
    
    foreach($arrParent as $parent_id):
        @$parent = $allCategory[$parent_id];
        if ($parent['left'] != 1) {
    ?>
        <a href="<?php echo BASE_URL?>/category/detail/?id=<?php echo $parent['category_id']?>"><?php echo $parent['admin_title']?></a> &raquo;
    <?php
        }
    endforeach;
    echo "Add Sub Category";
} else {
    echo "Add Category";
}
?>
</h1>
<?php
if ($this->message) {
?>
<div class="alertmessage">
    <?php echo $this->message?>
</div>
<?php
} // if has message
?>
<div style="padding:5px"></div>
<form action="" method="post">
    <input type="hidden" name="parent" id="parent" value="<?php echo $this->pa_id?>">
    <table width="70%" class="border">
        <thead>
            <tr>
                <td colspan="2">
                    Basic information
                </td>
            </tr>
        </thead>
        <tr>
            <td width="150">Category:*</td>
            <td><input type="text" name="admin_title" id="admin_title" class="input required"></td>
        </tr>
<?php
if ($pa_id <= 0) {
?>
        <tr>
            <td>Photo:</td>
            <td>
                <input type="text" name="main_image" id="main_image" class="input imageinput">
                <input type="button" id="getfile" value="Choose file" rel="main_image" class="getfile">
                <div id="showmain_image"></div>
            </td>
        </tr>
        <tr>
            <td>Photo link:</td>
            <td>
                <input type="text" name="photo_link" id="photo_link" class="input">
            </td>
        </tr>
        <tr>
            <td>Embed Youtube</td>
            <td>
                <textarea name="embed_youtube" id="embed_youtube" class="textarea"></textarea>
            </td>
        </tr>
        <tr>
            <td>Description</td>
            <td>
                <textarea name="description" id="description" class="textarea"></textarea>
            </td>
        </tr>
<?php
}
?>
        <tr>
            <td>Featured Category:</td>
            <td>
                <input type="checkbox" name="FeaturedCategory" id="FeaturedCategory" value="1">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="submit" name="submit">
                <input type="reset" value="Reset">
            </td>
        </tr>
    
    </table>
</form>

